// JKLogin

//商家的登录
function JKStoreLogin(pn, pw, authority) {
	
		JKjsonP({
			ws:"merchants/login",
			parameter:{username:pn, password:pw,authority:authority},
			sFunc:function(json){
			
				if(json.result=="success"){
					var telArr = localStorage.getItem("telPhones");
					
					if(telArr == null){
						telArr = new Array();
						telArr.push(pn);
					}else{
						telArr = new Array(telArr);
						var flag = true;
						for(var i = 0;i<telArr.length;i++){
							if(pn == telArr[i]){
								flag = false;
							}
						}
						if(flag){
						telArr.push(pn);
						}
					}
					localStorage.setItem("telPhones",telArr);
					localStorage.setItem("shopid",json.data.shop.id);
					localStorage.setItem("shopAdminId",json.data.shopAdmin.id);
					localStorage.setItem("maxDistance",json.data.shop.maxDistance);
					localStorage.setItem("openTime",json.data.shop.openTime);
					localStorage.setItem("closeTime",json.data.shop.closeTime);
					localStorage.setItem("code",json.data.shop.code);
					localStorage.setItem("address",json.data.shop.address);
					localStorage.setItem("shopName",json.data.shop.shopName);
					localStorage.setItem("LoginName", pn);
					
					var nextPage;
					if(authority=="main") {
						nextPage = "main.html";
						localStorage.setItem("loginAuthority", "main");	
					}else if(authority=="distribution") {
						nextPage = "distribution.html";	
						localStorage.setItem("loginAuthority", "distribution");	
					}else if(authority=="delivery") {
						nextPage = "delivery.html";	
						localStorage.setItem("loginAuthority", "delivery");	
						localStorage.setItem("subAdminId", json.data.shopAdmin.id);
					}
					localStorage.setItem("LoginName", pn);
					if("undefined" != typeof (mobile)){
						mobile.login(pn);
					}
					top.location=nextPage;
				}else{
					//alert(json.result);
					alert(json.msg);
				}
				
			},
			eFunc:function(XMLHttpRequest, textStatus, emessage){
				alert(emessage);
			}
		});		
}
	



	